package ${prefixPackage}.service.impl;

<#if !isSimple>
import ${prefixPackage}.beans.vo.${javaNameBig}Vo;
import ${prefixPackage}.beans.entity.${javaNameBig};
import ${prefixPackage}.mapper.${javaNameBig}Mapper;
import ${prefixPackage}.beans.request.${javaNameBig}AddRequest;
import ${prefixPackage}.beans.request.${javaNameBig}EditRequest;
import ${prefixPackage}.beans.request.${javaNameBig}ListRequest;
import ${prefixPackage}.service.${javaNameBig}Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinecai.common.constants.DelConstant;
import com.xinecai.common.exceptions.BootException;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
</#if>
<#if isSimple>
import ${prefixPackage}.beans.entity.${javaNameBig};
import ${prefixPackage}.mapper.${javaNameBig}Mapper;
import ${prefixPackage}.service.${javaNameBig}Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
</#if>

/**
 * ${tbDesc}Service实现层
 *
 * @author ${author}
 * @date ${date}
 */
@Service
public class ${javaNameBig}ServiceImpl extends ServiceImpl<${javaNameBig}Mapper, ${javaNameBig}> implements ${javaNameBig}Service {

    @Resource
    private ${javaNameBig}Mapper ${javaName}Mapper;
<#if !isSimple>

    @Override
    public void removeByIdLogic(Long id) {
        ${javaNameBig} entity = this.getById(id);
        if (Objects.isNull(entity) || entity.getDelFlag() == 1) {
            throw new BootException("查询对象不存在或者已经被删除");
        }
        entity.setDelFlag(DelConstant.DEL);
        this.updateById(entity);
    }

    @Override
    public IPage<${javaNameBig}Vo> listWithPage(${javaNameBig}ListRequest param) {
        Page<${javaNameBig}Vo> page = new Page<>(param.getPageNo(), param.getPageSize());
        List<${javaNameBig}Vo> list = ${javaName}Mapper.listWithPage(page, param);
        return page.setRecords(list);
    }

    @Override
    public ${javaNameBig}Vo getDTO(Long id) {
        ${javaNameBig} entity = this.getById(id);
        if (Objects.isNull(entity) || entity.getDelFlag() == 1) {
            throw new BootException("查询对象不存在或者已经被删除");
        }
        ${javaNameBig}Vo vo = new ${javaNameBig}Vo();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }

    @Override
    @Transactional(rollbackFor = {Throwable.class})
    public Long add${javaNameBig}(${javaNameBig}AddRequest addRequest) {
        ${javaNameBig} entity = new ${javaNameBig}();
        BeanUtils.copyProperties(addRequest, entity);
        this.save(entity);
        return entity.getId();
    }

    @Override
    @Transactional(rollbackFor = {Throwable.class})
    public void edit${javaNameBig}(${javaNameBig}EditRequest editRequest) {
        ${javaNameBig} entity = this.getById(editRequest.getId());
        if (Objects.isNull(entity) || entity.getDelFlag() == 1) {
            throw new BootException("查询对象不存在或者已经被删除");
        }
        BeanUtils.copyProperties(editRequest, entity);
        this.updateById(entity);
    }
</#if>
}
